package com.example.livedata.db.database;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;

import com.example.livedata.db.dao.UserDao;
import com.example.livedata.entity.UserInfo;

/**
 * Room数据库创建
 */

@Database(entities = {UserInfo.class}, version = 1)
public abstract class AppRoomDatabase extends RoomDatabase {

    private static AppRoomDatabase INSTANCE;

    public static AppRoomDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (AppRoomDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            AppRoomDatabase.class, "Sample.db")
                            .build();
                }
            }
        }
        return INSTANCE;
    }


    public abstract UserDao userDao();

}
